import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import '../../app_files.dart';
import 'widget/patrol_config_widget.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(PatrolOrderViewState state, Dispatch dispatch, ViewService viewService) {

  Widget _infoWidget() => Container(
    padding: EdgeInsets.only(left: 15, right: 15, bottom: 8),
    decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
            bottom: BorderSide(color: ThemeConfig.separeColor, width: 10))),
    child: Column(
      children: [
        Container(
          height: 44,
          child: Align(
            alignment: Alignment.centerLeft,
            child: Text(
              '管点信息',
              style: TextThemeConfig.Font16WithColorBold22,
            ),
          ),
          margin: EdgeInsets.only(bottom: 4),
        ),

        Container(
          padding: EdgeInsets.symmetric(vertical: 5),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                width: 85,
                child:  Text(
                  '工单编号',
                  style: TextThemeConfig.Font14WithColor66,
                ),
              ),
              Expanded(child: Text(
                state.pointInfo.orderID,
                style: TextThemeConfig.Font14WithColor22,
              ),)
            ],
          ),
        ),

        Container(
          padding: EdgeInsets.symmetric(vertical: 6),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                width: 85,
                child:  Text(
                  '巡检地址',
                  style: TextThemeConfig.Font14WithColor66,
                ),
              ),
              Expanded(
                child: Text(
                  state.pointInfo.pointAddress,
                  style:  TextThemeConfig.Font14WithMainColor,
                  overflow: TextOverflow.ellipsis,
                ),
              ),
            ],
          ),
        ),

        Container(
          padding: EdgeInsets.symmetric(vertical: 5),
          child: Row(
            children: [
              Container(
                width: 85,
                child: Text(
                  '管点编号',
                  style: TextThemeConfig.Font14WithColor66,
                ),
              ),
              Text(
                state.pointInfo.pointID,
                style: TextThemeConfig.Font14WithColor22,
              ),
            ],
          ),
        ),

        Container(
          padding: EdgeInsets.symmetric(vertical: 5),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                width: 85,
                child:  Text(
                  '管点名称',
                  style: TextThemeConfig.Font14WithColor66,
                ),
              ),
              Expanded(child: Text(
                state.pointInfo.pointName,
                style: TextThemeConfig.Font14WithColor22,
              ),)
            ],
          ),
        ),
      ],
    ),
  );

  Widget _bodyWidget() {
    if (state.items == null) {
      return Container(
        height: 500,
        child: Center(
          child: MyLoadingWidget(),
        ),
      );
    }

    List<Widget> list = state.items.map<Widget>((e) {
      return PatrolConfigWidget(e, dispatch);
    }).toList();
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: list,
    );
  }

  return Scaffold(
    appBar: myAppBar(viewService.context, title: '巡检工单'),
    body: SafeArea(
      child: GestureDetector(
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              _infoWidget(),
              // _gasInfoWidget(),
              _bodyWidget(),
              Container(
                margin: EdgeInsets.symmetric(horizontal: 15, vertical: 40),
                height: 50,
                decoration: BoxDecoration(
                  color: ThemeConfig.mainColor,
                  borderRadius: BorderRadius.all(Radius.circular(4)),
                ),
                child: InkWell(
                  child: Align(
                    child: Text(
                      '下一步',
                      style: TextThemeConfig.Font16WithWhite,
                    ),
                  ),
                  onTap: () => dispatch(PatrolOrderViewActionCreator.onSubmit()),
                ),
              )
            ],
          ),
        ),
        behavior: HitTestBehavior.translucent,
        onTap: () => CommonUtils.closeKey(viewService.context),
      ),
    ),
  );
}
